define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'service/skill/perfect/index' + location.search,
                    add_url: 'service/skill/perfect/add',
                    // edit_url: 'service/skill/perfect/edit',
                    // del_url: 'service/skill/perfect/del',
                    multi_url: 'service/skill/perfect/multi',
                    import_url: 'service/skill/perfect/import',
                    table: 'service_apply_skill',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'updatetime',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {field: 'id', title: __('服务者信息'),operate: false,formatter:function (value,row){
                            let result = `<div style="display: flex;">
        <img style="width: 100px;height: 100px;" src="${row.image}"/>
        <div style="margin-left: 16px;flex:1;">
            <div style="display: flex;align-items: center">
                <span  style="font-size: 16px;color: #333;">${row.name}</span>
                <div style="background: rgba(248, 118, 121, 0.10);height: 26px;display: flex;align-items: center;padding: 0 8px;border-radius: 13px;margin-left: 8px;color: rgba(248, 118, 121, 1)">ID：${row.id}</div>
                
                <div style="background: rgba(123, 101, 251, 0.10);height: 26px;display: flex;align-items: center;padding: 0 8px;border-radius: 13px;margin-left: 8px;color: #7B65FB">${row.skill_cate_name}</div>
                <div style="flex: 1"></div>`
                
                result += `
                
            </div>
        
            <div style="color: #333333;font-size: 14px;margin-top: 8px;display: flex;align-items: center;">
                <span style="color: #333;font-size: 14px;margin-right: 8px;">${row.sex_text}</span><span>身份证：</span>${row.idcard}
            </div>
            <div style="display: flex;align-items: center;margin-top: 8px;">
                <div style="background: #F0FAF3;height: 26px;display: flex;align-items: center;padding: 0 8px;border-radius: 13px;margin-right: 8px;"><span style="color: #999999">学历：</span>${row.edu_text}</div>
                <div style="background: #EFF5FF;height: 26px;display: flex;align-items: center;padding: 0 8px;border-radius: 13px;margin-right: 8px;"><span style="color: #999999">年龄：</span>${row.age}</div>
                <div style="background: #F6F1FF;height: 26px;display: flex;align-items: center;padding: 0 8px;border-radius: 13px;margin-right: 8px;"><span style="color: #999999">民族：</span>${row.nation}</div>
                <div style="background: #FFF7E6;height: 26px;display: flex;align-items: center;padding: 0 8px;border-radius: 13px;"><span style="color: #999999">经验：</span>${row.exper_text}</div>
            </div>
            <div style="display: flex;align-items: center;margin-top: 8px;width: 100%;">
                <div style="width: 100%;background: #F7F7F7;display: flex;align-items: center;padding: 8px;border-radius: 6px;"><span style="color: #999999">所在位置：</span>${row.province}${row.city}${row.district}${row.address}</div>
            </div>
           
        </div>
    </div>`
                            return  result
                        }},
                        
                       
                        {field: 'id', title: __('证件'),operate: false,formatter:function (value,row){
                            return `
                           <div style="display: flex;align-items: center;border-bottom: 1px solid #EEEEEE; padding: 10px 0;">
        <div style="display: flex;flex-direction: column;align-items: center;margin-right: 10px;">
            <img src="${row.front_image}" alt="" style="width: 56px;height: 56px;border-radius: 8px;margin-bottom: 8px;">
            <span style="color: #999999;font-size: 12px;">身份证正面</span>
        </div>
        <div style="display: flex;flex-direction: column;align-items: center;">
            <img src="${row.opposite_image}" alt="" style="width: 56px;height: 56px;border-radius: 8px;margin-bottom: 8px;">
            <span style="color: #999999;font-size: 12px;">身份证反面</span>
        </div>
    </div>
    <div style="display: flex;align-items: center;padding: 10px 0 0;">
        <div style="display: flex;flex-direction: column;align-items: center;margin-right: 10px;">
            <img src="${row.certificate_image}" alt="" style="width: 56px;height: 56px;border-radius: 8px;margin-bottom: 8px;">
            <span style="color: #999999;font-size: 12px;">从业资格证</span>
        </div>
        <div style="display: flex;flex-direction: column;align-items: center;">
            <img src="${row.health_image}" alt="" style="width: 56px;height: 56px;border-radius: 8px;margin-bottom: 8px;">
            <span style="color: #999999;font-size: 12px;">健康证</span>
        </div>
    </div>
                            `
                        }},
                        {field: 'id', title: __('服务项目'),operate: false,cellStyle: function () {return {css: {"min-width": "300px","max-width": "500px"}}},formatter:function (value,row){
                            let word = row.goodsname.split(',')
                            let result = '<div style="color: #333;font-size: 14px;margin-bottom: 8px;flex-wrap: wrap;display: flex;align-items: center">';
                            for(let i=0; i < word.length; i++){
                                result += `<div style="margin: 0 8px 8px;">${word[i]}</div>`
                            }
                            result+='</div>'
                            return result
                        }},
                        {field: 'id', title: __('照片'),operate: false,formatter:function (value,row){
                            let images = row.images.split(',')
                            let result = `<div style="display: flex;align-items: flex-start;flex-direction: column;border-bottom: 1px solid #EEEEEE; padding: 10px 0;">
                           <span style="color: #999999;font-size: 12px;">实拍照</span>
        <div style="display: flex;flex-direction: column;align-items: center;margin-top: 8px;">
            
            <img src="${row.user_image}" alt="" style="width: 56px;height: 56px;border-radius: 8px;">
            
        </div>

    </div>`;
    if(row.images.length>0){
        result+=`<div style="display: flex;align-items: flex-start;flex-direction: column;padding: 10px 0 0;margin-top: 8px;">
        <span style="color: #999999;font-size: 12px;">相册</span>
        <div style="display: flex;align-items: center;margin-top: 8px;">`;
        for(let i=0; i < images.length; i++){
                                result += `<img src="${images[i]}" alt="" style="width: 56px;height: 56px;margin-right:5px;border-radius: 8px;">`
                            }
                            result+='</div></div>'
    }
                            return  result
                        }},
                        {field: 'id', title: __('状态'),operate: false, cellStyle: function () {return {css: {"max-width": "400px","min-width": "300px"}}},formatter:function (value,row){
                            let result = `    <div style="display: flex;align-items: center;justify-content:space-between;padding: 0 20px;width: 250px;height: 66px;">
        <span style="font-size: 14px;color: #999;">状态</span>
        <span style="color: #1677FF;font-size: 14px;">${row.state_text}</span>
    </div>`
                             if(row.state == -1){
                                 result+=`
                                 <div style="display: flex;align-items: flex-start;justify-content:space-between;width: 250px;height: 66px;white-space:normal;padding:20px 20px 0;border-top: 1px solid #EEEEEE;">
        <div style="font-size: 14px;color: #999;flex-shrink:0;">拒绝原因</div>
        <div style="color: #FF1F2B;font-size: 14px;text-align:left;margin-left:20px;white-space: pre-line;">${row.note}</div>
    </div>
                            `
                             }
                             return result
                        }},
                         {field: 'id', title: __('时间'),operate: false, cellStyle: function () {return {css: {"min-width": "180px"}}},formatter:function (value,row){
                            return `
                           <div style="margin-bottom: 10px;">
        <div style="color: #999999;font-size: 14px;margin-bottom: 8px;text-align:left;">创建时间</div>
        <div style="color: #333333;font-size: 14px;text-align:left;">${row.create_time}</div>
    </div>
    <div>
        <div style="color: #999999;font-size: 14px;margin-bottom: 8px;text-align:left;">更新时间</div>
        <div style="color: #333333;font-size: 14px;text-align:left;">${row.update_time}</div>
    </div>
                            `
                        }},
                        // {checkbox: true},
                        {field: 'id', title: __('Id'),visible: false},
                        {field: 'user_id', title: __('User_id'),visible: false},
                        {field: 'applytype', title: __('Applytype'), searchList: {"0":__('Applytype 0'),"1":__('Applytype 1')}, formatter: Table.api.formatter.normal,visible: false},
                        {field: 'name', title: __('Name'),visible: false},
                        {field: 'sex', title: __('Sex'), searchList: {"1":__('Sex 1'),"0":__('Sex 0')}, formatter: Table.api.formatter.normal,visible: false},
                        {field: 'idcard', title: __('Idcard'),visible: false},
                        // {field: 'front_image', title: __('Front_image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        // {field: 'opposite_image', title: __('Opposite_image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        // {field: 'user_image', title: __('User_image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        // {field: 'certificate_image', title: __('Certificate_image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        // {field: 'health_image', title: __('Health_image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'category.name', title: __('Category_id'),visible: false},
                        {field: 'cate.name', title: __('Skill_cate_id'),visible: false},
                        {field: 'goodsname', title: __('服务项目'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content,visible: false},
                        {field: 'image', title: __('Image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image,visible: false},
                        // {field: 'images', title: __('Images'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.images},
                        {field: 'edu', title: __('Edu'), searchList: {"0":__('Edu 0'),"1":__('Edu 1'),"2":__('Edu 2'),"3":__('Edu 3'),"4":__('Edu 4'),"5":__('Edu 5'),"6":__('Edu 6')}, formatter: Table.api.formatter.normal,visible: false},
                        {field: 'nation', title: __('Nation'),visible: false},
                        {field: 'height', title: __('Height'),visible: false},
                        {field: 'weight', title: __('Weight'),visible: false,operate: false},
                        {field: 'exper', title: __('Exper'), searchList: {"0":__('Exper 0'),"1":__('Exper 1'),"2":__('Exper 2'),"3":__('Exper 3')}, formatter: Table.api.formatter.normal,visible: false},
                        {field: 'province', title: __('Province'), operate: 'LIKE',visible: false},
                        {field: 'city', title: __('City'), operate: 'LIKE',visible: false},
                        {field: 'district', title: __('District'), operate: 'LIKE',visible: false},
                        {field: 'address', title: __('Address'), operate: 'LIKE',visible: false},
                        {field: 'lng', title: __('Lng'),visible: false,operate: false},
                        {field: 'lat', title: __('Lat'),visible: false,operate: false},
                        {field: 'note', title: __('Note'), operate: 'LIKE',visible: false},
                        {field: 'state', title: __('State'), searchList: {"0":__('State 0'),"1":__('State 1'),"-1":__('State -1')}, formatter: Table.api.formatter.normal,visible: false},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime,visible: false},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime,visible: false},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate,
                            buttons: [
                                {
                                    name:'audit',
                                    text:'通过',
                                    title:'通过',
                                    classname: 'btn btn-xs btn-success btn-ajax',
                                    url: 'service/skill/perfect/agree',
                                    success: function (data, ret) {
                                        $(".btn-refresh").trigger('click');
                                    },
                                    hidden:function(row){
                                        if(row.state != 0){
                                            return true;
                                        }
                                    }
                                },
                                {
                                    name: 'refuse',
                                    text: __('拒绝'),
                                    title: __('拒绝'),
                                    classname: 'btn btn-xs btn-danger btn-dialog',
                                    url: function(row){
                                        return 'service/skill/perfect/refuse?ids='+row.id;
                                    },
                                    success: function (data, ret) {
                                        $(".btn-refresh").trigger('click');
                                    },
                                    hidden:function(row){
                                        if(row.state != 0){
                                            return true;
                                        }
                                    }
                                },
                            ],
                            formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        agree: function () {
            
            $(document).on('click', '.btn-embossed', function () {
                parent.$(".btn-refresh").trigger('click');
            });
            Controller.api.bindevent();
        },
        refuse: function () {
            
            $(document).on('click', '.btn-embossed', function () {
                parent.$(".btn-refresh").trigger('click');
            });
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
